package com.circle.interests.biz.controller;

import com.circle.common.core.utils.R;
import com.circle.interests.biz.enums.SceneTypeEnum;
import com.circle.interests.biz.service.IPrizeWinRecordService;
import com.circle.prize.library.api.dto.PrizeReceiveResultDto;
import com.circle.prize.library.api.dto.PrizeWinResultDto;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author zhou
 * @date 2021/12/11
 */
@Slf4j
@Api(tags = {"测试接口"})
@RestController
@RequestMapping("test")
@ApiSupport(author = "周福寿")
public class TestController {

    @Resource
    private IPrizeWinRecordService prizeWinRecordService;

    @ApiOperation("中奖")
    @GetMapping("/win")
    public R<PrizeWinResultDto> win(@ApiParam(value = "活动code") @RequestParam(value = "sceneId") String sceneId,
                                    @ApiParam(value = "用户openId") @RequestParam(value = "openId") String openId,
                                    @ApiParam(value = "用户openId") @RequestParam(value = "prizeCode") String prizeCode,
                                    @ApiParam(value = "用户openId") @RequestParam(value = "price", required = false) Integer price) {
        PrizeWinResultDto resultDto = prizeWinRecordService.winPrize(SceneTypeEnum.ACT.getCode(), sceneId, openId, prizeCode, 1, price);
        return R.success(resultDto);
    }

    @ApiOperation("领奖")
    @GetMapping("/receivePrize")
    public R<PrizeReceiveResultDto> writeOff(@ApiParam(value = "中奖id") @RequestParam(value = "recordId", required = false) Long recordId,
                                             @ApiParam(value = "核销二维码") @RequestParam(value = "writeOffQrCode", required = false) String writeOffQrCode) {
        PrizeReceiveResultDto resultDto = prizeWinRecordService.receivePrize(recordId, writeOffQrCode);
        return R.success(resultDto);
    }

    @ApiOperation("核销奖品")
    @GetMapping("/writeOff")
    public R<?> deleteUser(@ApiParam(value = "活动code") @RequestParam(value = "sceneId", required = false) String sceneId,
                           @ApiParam(value = "手机号") @RequestParam(value = "phoneNumber", required = false) String phoneNumber,
                           @ApiParam(value = "核销码") @RequestParam(value = "writeOffCode", required = false) String writeOffCode,
                           @ApiParam(value = "备注") @RequestParam(value = "remark", required = false) String remark) {
        prizeWinRecordService.writeOff(SceneTypeEnum.ACT.getCode(), sceneId, phoneNumber, writeOffCode, remark);
        return R.success();
    }

}
